#!/usr/bin/env bash

if [ `whoami` != "root" ];then
  echo "must be root"
  exit 1
fi

if [ -n "$M2_HOME" ]; then
  echo   "maven已存在"
  exit
fi

echo "安装maven..."
wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz -P /opt -N
tar -zxf /opt/apache-maven-3.6.*.tar.gz -C /opt/
path2=`ls -F /opt | grep '/$'| grep apache-maven-3. | sed 's/.$//'`
echo -e "\n# M2_HOME \n \
export M2_HOME=/opt/$path2 \n \
export PATH=\$M2_HOME/bin:\$PATH " | sudo tee -a /etc/profile
source /etc/profile
